package com.spider.silence.main;

import com.spider.silence.downloader.WyzxDownloader;
import com.spider.silence.pool.WyzxDownloaderPool;
import com.spider.silence.utils.PropertiesUtil;
import com.spider.silence.worker.MaLaWorker;
import com.spider.silence.worker.MalaModuleWorker;
import com.spider.silence.worker.WyzxModuleWorker;
import com.spider.silence.worker.WyzxWorker;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by qiuhao on 2017/5/15.
 */
public class WyzxMain {
    public static void main(String[] args){
        WyzxDownloaderPool pool = null;
        WyzxDownloader downloader = null;

        try{
            pool = WyzxDownloaderPool.getInstance();
            downloader = pool.fetchDownLoader(1000);
            List<Map<String,Object>> urlList = downloader.getUrlList();
            //生成任务队列
            downloader.generateTask(urlList);
            ExecutorService service =  Executors.newFixedThreadPool(3000);
            for(int i = 0; i<Integer.valueOf(PropertiesUtil.getVal("MaLa.WorkerCount")); i++){
                service.execute(new WyzxModuleWorker());
                service.execute(new WyzxWorker());
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            if(downloader != null){
                pool.releaseDownLoader(downloader);
            }
        }
    }
}
